import { createRouter, createWebHashHistory } from 'vue-router'
import layout from '../layout/index.vue'
import NProgress from 'nprogress'
import GuahaoIcon from '../assets/images/guahao-icon.png'
import HomeIcon from '../assets/images/shouyeshuju.png'
import InterrogationIcon from '../assets/images/zl-icon.png'
import PatientIcon from '../assets/images/patient-icon.png'
import DoctorIcon from '../assets/images/doctor-icon.png'

import store  from '../store/index.js'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: layout,
      redirect:"/home",
      children: [
        {
          path: '/home',
          name: 'Home',
          meta:{
            icon:HomeIcon,
            activeIcon:HomeIcon,
            title:"首页数据",
            activeRoute:"Home"
          },
          component: () => import('../views/Home/Index.vue'),
          children:[
          ]
        },
		{
		  path: '/appointment',
		  name: 'Appointment',
		  meta:{
		    icon:GuahaoIcon,
		    activeIcon:GuahaoIcon,
		    title:"预约挂号",
		    activeRoute:"Appointment"
		  },
		  component: () => import('../views/Appointment/index.vue'),
		  children:[
		      {
		        path: '/data-test',
		        name: 'DataTest',
		        meta:{
		          title:"预约列表",
		          activeRoute:"Appointment"
		        },
		        component: () => import('../views/Appointment/DataTest/Index.vue'),
		      },
			  {
			    path: '/newappointment',
			    name: 'NewAppointment',
			    meta:{
			      title:"手动预约",
			      activeRoute:"NewAppointment"
			    },
			    component: () => import('../views/Appointment/NewAppointment/index.vue'),
			  },
		  ]
		},
		{
		  path: '/interrogation',
		  name: 'Interrogation',
		  meta:{
		    icon:InterrogationIcon,
		    activeIcon:InterrogationIcon,
		    title:"问诊治疗",
		    activeRoute:"Interrogation"
		  },
		  component: () => import('../views/Interrogation/index.vue'),
		  children:[
		      {
		        path: '/interrogationlist',
		        name: 'InterrogationList',
		        meta:{
		          title:"问诊列表",
		          activeRoute:"Interrogation"
		        },
		        component: () => import('../views/Interrogation/InterrogationList/Index.vue'),
		      },
		  ]
		},
		{
		  path: '/patientservice',
		  name: 'PatientService',
		  meta:{
		    icon:PatientIcon,
		    activeIcon:PatientIcon,
		    title:"患者服务",
		    activeRoute:"PatientService"
		  },
		  component: () => import('../views/PatientService/Index.vue'),
		  children:[
		      {
		        path: '/patientlist',
		        name: 'PatientList',
		        meta:{
		          title:"患者列表",
		          activeRoute:"PatientService"
		        },
		        component: () => import('../views/PatientService/PatientList/Index.vue'),
		      },
		  ]
		},
		{
		  path: '/doctormanagement',
		  name: 'DoctorManagement',
		  meta:{
		    icon:DoctorIcon,
		    activeIcon:DoctorIcon,
		    title:"医生管理",
		    activeRoute:"DoctorManagement"
		  },
		  component: () => import('../views/DoctorManagement/Index.vue'),
		  children:[
		      {
		        path: '/doctorlist',
		        name: 'DoctorList',
		        meta:{
		          title:"医生列表",
		          activeRoute:"DoctorManagement"
		        },
		        component: () => import('../views/DoctorManagement/DoctorList/Index.vue'),
		      },
		  ]
		}
      ]
    },
    {
      path: '/login',
      name: 'login',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Login/Index.vue')
    }
  ]
})
router.beforeEach(async(to, from, next) => {
  NProgress.start();
  // if (!store.state.common.menus.length) {
  //   store.commit("common/MENUS", menus);
  // }
  // let { info, dict, allCategoryList, btnAuthList, dataAuthList, routerPath, merchantHall } = store.state.common;
  // let { path, matched } = to;
  // if (!matched.length) {
  //   next({ path: "/404", replace: true });
  // } else if (whitelist.includes(path)) {
  //   next();
  // } else if (info && info.access_token) {
  //   next();
  // } else {
  //   next("/login");
  // }
  let tabList = store.state.common.tabList
  if(tabList.length){
    if(tabList.findIndex(item => item.path === to.path) === -1){
      await store.commit("common/ADDTABLIST", to);
    }
  }else{
    await store.commit("common/ADDTABLIST", to);
  }
  next()
});
router.afterEach(() => {
  NProgress.done()
})
export default router
